<extend name="layout/edit" />

<block name="HEADER">
    <load:css src="system/userMng/index.css" />
</block>

<block name="CONTENT">
    <control:form id="form"/>
</block>

<block name="FOOTER">
   <script type="text/javascript">
    var  page=(function(ns){
        
        var tree;
        
        //页面初始化
        ns.init=function(){
        	if(window.__mode!=1){
        	    form.setReadonly('user_code',false);
        	}
        }
        
        //选择公司
        ns.selectOrg=function(){
            function successFn(){
                tree=layui.tree.render({
                    elem: '#selectOrg' ,
                    textField:"org_name",
                    idField:"org_id",
                    parentField:'parent_org_id',
                    data:'/admin/soft/system_user/getOrgData',
                    isList:true,                         //是否列表结构数据，如果是，idField，parentField 必填
                    expandNode:1,                //可选，默认展开的节点，字符串
                    showIcon:function(e){       //显示图标，可为true
                        return e.parent_org_id == 0 ? "&#xe641;" : '&#xe66b;';
                    },
                    loadSuccess:function(data){  //加载成功
                        data[0] && tree.selectNode("org_id", form.getValue("org_id") );
                    }
                });
            }
            function yesFn(index){
                var  node = tree.getSelectedNode(); 
                form.setValue("org_id",node.org_id);
                form.setValue("org_name",node.org_name);
                layer.close(index);
            }
            var html="<div id='selectOrg'></div>";
            $.openModalDialog(html,"置换组织",successFn,yesFn,["350px","370px"])
        }
        
        //保存
        ns.add=function(){
            if(__mode==1){
                var param = form.getData();
                if(param){
                    $.ajaxs("/admin/soft/system_user/addUser",param,function(res){
                        form.opener.$.toast(1,"新增成功！");
                        form.opener.grid.load();
                        form.close();
                    });
                }
            }else{
                form.save(1).then(function(res){
                    form.opener.grid.load();
                });
            }
        }
        
        return ns;
    }({}));
    
    $(function(){  page.init();  });
   </script>
</block>





